package com.jiyinit.web.core.activiti.dao;

import com.jiyinit.core.framework.base.entity.BaseEntity;
import com.jiyinit.core.framework.base.paging.PagingResult;
import com.jiyinit.core.framework.dao.mybatis.base.MybatisDaoContext;
import com.jiyinit.core.framework.dao.mybatis.paginator.domain.PageBounds;
import com.jiyinit.web.core.activiti.dto.LeaveBillRequset;
import com.jiyinit.web.core.activiti.entity.TabLeaveBillInfoEntity;
import com.jiyinit.web.core.activiti.vo.TabLeaveBillinfoVo;
import com.jiyinit.web.core.common.util.Map2Bean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("core.tabLeaveBillInfoDao")
public class TabLeaveBillInfoDao {

    /**
     * 日志对象
     */
    private static Logger logger = LoggerFactory.getLogger(TabLeaveBillInfoDao.class);

    private String SQLID = "core.tabLeaveBillInfoDao.";

    @Autowired
    @Qualifier("core.MybatisDaoContext")
    private MybatisDaoContext mybatisDaoContext;


    public int deleteByPrimaryKey(Integer id)
    {
        Map keyMap=new HashMap<>();
        keyMap.put("id",id);
        return mybatisDaoContext.delete(SQLID+"deleteByPrimaryKey",keyMap);
    }


    public int insert(TabLeaveBillInfoEntity record)
    {
        return mybatisDaoContext.save(SQLID+"insert",record);
    }


    public int insertSelective(TabLeaveBillInfoEntity record)
    {
        return mybatisDaoContext.save(SQLID+"insertSelective",record);
    }

    public TabLeaveBillInfoEntity selectByPrimaryKey(Integer id)
    {
        Map keyMap=new HashMap<>();
        keyMap.put("id",id);
        return mybatisDaoContext.findOne(SQLID+"selectByPrimaryKey",TabLeaveBillInfoEntity.class,keyMap);
    }

    public List<TabLeaveBillInfoEntity> findBySelective(TabLeaveBillInfoEntity record)
    {
        Map<String, Object> map=Map2Bean.beanToMap(record);
        return mybatisDaoContext.findAll(SQLID+"findBySelective",TabLeaveBillInfoEntity.class,map);
    }

    public PagingResult<TabLeaveBillInfoEntity> getUserInfoListByCondiction(LeaveBillRequset record){
        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(record.getLimit());
        pageBounds.setPage(record.getPage());
        return mybatisDaoContext.findForPage(SQLID + "findBySelective", TabLeaveBillInfoEntity.class, record, pageBounds);
    }

    public int updateByPrimaryKeySelective(TabLeaveBillInfoEntity record)
    {
        return mybatisDaoContext.update(SQLID+"updateByPrimaryKeySelective",record);
    }

    public int updateByPrimaryKey(TabLeaveBillInfoEntity record)
    {
        return mybatisDaoContext.update(SQLID+"updateByPrimaryKey",record);
    }

    /*txd 添加开始*/
    /**
     * 请假信息统计(导出)
     * @param requset
     * @return
     */
    public List<TabLeaveBillinfoVo> findLeaveInfoListForExport(LeaveBillRequset requset){
        return mybatisDaoContext.findAll(SQLID+ "findLeaveInfoListForExport", TabLeaveBillinfoVo.class, requset.toMap());
    }

    /**
     * 请假信息统计(分页, 导出)
     * @param requset
     * @return
     */
    public PagingResult<TabLeaveBillinfoVo> findLeaveInfoListForExportByPage(LeaveBillRequset requset){
        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(requset.getLimit());
        pageBounds.setPage(requset.getPage());
        return mybatisDaoContext.findForPage(SQLID+ "findLeaveInfoListForExport", TabLeaveBillinfoVo.class, requset, pageBounds);
    }

    /**
     * 获取当前用户的待提交的最大id,即为最新id
     * @param userId
     * @return
     */
    public int getMaxIdByUserId(Integer userId){
        return mybatisDaoContext.findOne(SQLID+ "getMaxIdByUserId", Integer.class, userId);
    }

    public PagingResult<TabLeaveBillinfoVo> find(LeaveBillRequset request) {
        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(request.getLimit());
        pageBounds.setPage(request.getPage());
        return mybatisDaoContext.findForPage(SQLID + "find", TabLeaveBillinfoVo.class, request.toMap(), pageBounds);
    }
}